package org.liukai.tutorial.domain;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.persistence.Transient;

import org.liukai.tutorial.utils.ConvertUtils;

import com.google.common.collect.Lists;

/**
 * 用户
 * 
 * @author liukai
 * 
 */
public class User implements Serializable {

	private static final long serialVersionUID = 1335306439933341280L;

	private Integer id;

	private String email;

	private String loginName;

	private String name;

	private String password;

	private List<Role> roleList = Lists.newArrayList();// 有序的关联对象集合

	// 用于在页面以checkbox显示拥有的Role列表
	public Map<Integer, Integer> roleCheckBox;

	/**
	 * 用户拥有的角色名称字符串,多个角色用','分隔.
	 */
	// 非持久化属性
	@Transient
	public String getRoleNames() {
		return ConvertUtils.convertElementPropertyToString(roleList, "name",
				",");
	}

	/**
	 * 用户拥有的角色id字符串, 多个角色id用','分隔.
	 */
	// 非持久化属性.
	@Transient
	@SuppressWarnings("unchecked")
	public List<Integer> getRoleIds() {
		return ConvertUtils.convertElementPropertyToList(roleList, "id");
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public List<Role> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}

	public Map<Integer, Integer> getRoleCheckBox() {
		return roleCheckBox;
	}

	public void setRoleCheckBox(Map<Integer, Integer> roleCheckBox) {
		this.roleCheckBox = roleCheckBox;
	}
}
